<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script>
    let arr1 = ["a", "b", "c", "d"]
    for (let i = 0; i < arr1.length; i++) {
        console.log(i, arr1[i])
    }

    arr1.forEach(function (val, index, arr) {
        console.log(val, index, arr)
    });
    // a 0 (4) ["a", "b", "c", "d"]
    // b 1 (4) ["a", "b", "c", "d"]
    // c 2 (4) ["a", "b", "c", "d"]
    // d 3 (4) ["a", "b", "c", "d"]
    //  todo 遍历 与上面方法 output 一样
    arr1.forEach((...args) => {
        console.log(...args)
    });

    let test = () => {
        a = 1;
        arr1.forEach((...args) => {
            console.log(this.a); // 这个this 代表当前 函数 this.a =1
            console.log(...args)
        });
    };
    test();

    json = [
        {"a": 1, "b": 2, "c": 3},
        {"a": 11, "b": 22, "c": 33},
        {"a": 111, "b": 22, "c": 333},
        {"a": 1111, "b": 2222, "c": 3333},
    ];
    //todo 数组 map方法
    let test1 = () => {
       newjson = json.map((val, index, arr) => {
            console.log(`a:${val.a},b:${val.b},c:${val.c},index:${index}`);
            return {"a": val.a * 2, "b": val.b * 2, "c": val.c ** 2}
        });
        console.log("MAP后新数组:", ...this.newjson) //MAP后新数组: {a: 2, b: 4, c: 9} {a: 22, b: 44, c: 1089} {a: 222, b: 44, c: 110889} {a: 2222, b: 4444, c: 11108889}
    };
    test1();
    let aabc = 1;
    let b = aabc == 1 && 2 ;
    console.log(b)

    //todo 数组复制
    console.log(`======================${"复制数组"}================================`)
    arr123 = [1,2,3];;
    console.log(`原始数组:${arr123}`);
    arr1234 = [...arr123];
    console.log(`复制数组:${arr123}`);
    arr12345 = Array.from(arr123);
    console.log(`复制数组:${arr12345}`);
    let arr111 = []
    Object.assign(arr111,arr123);
    console.log(arr111)


    console.log(`======================${"转化为数组"}================================`)
    let data = {
       0:"11",
       1:"22",
       3:"33"
    };
    console.log(Array.from(data)) // 这里没有东西 没有length 属性
    data.length = 2; // 添加length属性 只能用在key是数字的情况下
    console.log(Array.from(data)) // ["11","22"]

    //todo 值转数组
    console.log(`======================${"值转数组"}================================`)
    let arr11 = Array.of("aa","bb","cc")
    console.log(arr11)

    let arrformat = (...arr1)=>{
        return arr1
    };
    console.log(arrformat("aa","bb","cc"))

    //todo 数组find
    console.log(`======================${"数组find"}================================`)
    let ff = arr11.find((val,index,arr)=>{  // 还有个findIndex方法
        return val.startsWith("aa") // 把每个返回true的返回
    });
    console.log(ff) // aa

    //todo 数组includes
    console.log(`======================${"数组includes"}================================`)
    console.log(`${arr1}是否包含${"aa"}:${arr11.includes("aa")}`) // true
</script>
<body>

</body>
</html>